<?php

namespace app\health\model;

use think\Model;

class HealthUserSignIn extends Model
{
    // 表名
    protected $name = 'health_user_sign_in';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;

    protected $append = [
        'reward_type_text',
        'day_text'
    ];

    /**
     * 获取奖励类型描述
     * @param [type] $val
     * @param [type] $data
     * @Author 张旭鹏
     * @DateTime 2023-07-03
     */
    public function getRewardTypeTextAttr($val, $data)
    {
        $rewardType = $data['reward_type'] ?? -1;
        $map        = [-1 => '未定义', 0 => '无奖励', 1 => '余额', 2 => '鑫积分'];
        return $map[$rewardType] ?? '-';
    }

    /**
     * 签到天数描述
     * @param [type] $val
     * @param [type] $data
     * @Author 张旭鹏
     * @DateTime 2023-07-03
     */
    public function getDayTextAttr($val, $data)
    {
        return '第' . ($data['day'] ?? 0) . '天';
    }
}
